//
//  SystemFilePath.m
//  FileSystemDemo
//
//  Created by 小草毋正 on 2018/1/3.
//  Copyright © 2018年 zwc. All rights reserved.


#import "SystemFilePath.h"

@implementation SystemFilePath


/** 获取 Library 目录路径 */
+ (NSString *)documentPath {
    return [self pathWithDirectory:NSDocumentDirectory];
}

/** 获取 Library 目录路径 */
+ (NSString *)libraryPath {
    return [self pathWithDirectory:NSLibraryDirectory];
}

/** 获取 Caches 目录路径 */
+ (NSString *)cachesPath {
    return [self pathWithDirectory:NSCachesDirectory];
}

/** 获取 temp（tmp） 目录路径 */
+ (NSString *)tempPath {
    return NSTemporaryDirectory();
}


+ (NSString *)homePath {
    return NSHomeDirectory();
}


/**
 * @abstract 获取目录路径
 * @discussion 该方法只针对在这里只 docments,library,caches三种类型的文件，其他类型暂未尝试
 * @result 目录路径
 */
+ (NSString *)pathWithDirectory:(NSSearchPathDirectory)directory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
    if(paths == nil || paths.count <= 0){
        return nil;
    }
    else {
        return [paths firstObject];
    }
}


@end
